class Solution {
public:
    int maxDepth(TreeNode* root) {
        int ans = 0;
        if (root == nullptr)
        {
            return 0;
        }
        queue<TreeNode*> q;
        q.push(root);
        while (q.size())
        {
            int sz = q.size();
            for (int i = 0; i < sz; i++)
            {
                TreeNode* tmp = q.front();
                q.pop();
                if (tmp->left) q.push(tmp->left);
                if (tmp->right) q.push(tmp->right);
            }
            ans++;
        }
        return ans;
    }
};